package com.bloody.android;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;

import com.bloody.android.Map.DrawableCaseFactory;

public abstract class ViewObject{

	private Drawable tile;
	private Bitmap bitmap;
	
	public ViewObject(Context context, int id){
		tile = DrawableCaseFactory.getDrawable(id, context);
	}
	
	public Drawable getTile(){
		return tile;
	}
	
	public void createIm(int tileSize){
		bitmap = Bitmap.createBitmap(tileSize, tileSize, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
        tile.setBounds(0, 0, tileSize, tileSize);
        tile.draw(canvas);
	}
	
	public abstract int getPosx();
	
	public abstract int getPosy();
	
	public void draw(Canvas canvas, int mXOffset, int mYOffset, int mTileSize, Paint paint, int xmin, 
			int xmax, int ymin, int ymax){
		int posx = getPosx();
		int posy = getPosy();
		
		if(posx>=xmin && posx<=xmax && posy>=ymin && posy<=ymax){
			draw(getBitmap(), canvas, mXOffset, mYOffset, mTileSize, paint, xmin, xmax, ymin, ymax);
		}
	}
	
	public void draw(Bitmap bitmap, Canvas canvas, int mXOffset, int mYOffset, int mTileSize, Paint mPaint, int xmin, 
			int xmax, int ymin, int ymax){
		
		int posx = getPosx();
		int posy = getPosy();

		canvas.drawBitmap(bitmap, 
                mXOffset + (posx-xmin) * mTileSize,
                mYOffset + (posy-ymin) * mTileSize,
                mPaint);
	}
	
	public Bitmap getBitmap(){
		return bitmap;
	}
	
	public void setBitmap(Bitmap bitmap){
		this.bitmap = bitmap;
	}

}
